#ifndef __SYSCALLLIB_H
#define __SYSCALLLIB_H

long syscall_intface0(long nr);
long syscall_intface1(long nr, long pval1);
long syscall_intface2(long nr, long pval1, long pval2);
long syscall_intface3(long nr, long pval1, long pval2, long pval3);
long syscall_intface4(long nr, long pval1, long pval2, long pval3, long pval4);
long syscall_intface5(long nr, long pval1, long pval2, long pval3, long pval4, long pval5);
long syscall_intface6(long nr, long pval1, long pval2, long pval3, long pval4, long pval5, long pval6);

#define __NR_exit 93
#define __NR_getpid 172
void uexit(int code);

long ugetpid(void);


/**
 * 处理0个参数
 */
#define API_ENTRY_PARE0(nr,rets) \
asm volatile(\
         "move a7, %[sysnr]\n\t"\
         "ecall \n\t"\
		 "move %[retval], a0 \n\t"\
         :[retval] "=r" (rets)\
         :[sysnr] "r" (nr)\
         :"a7","a0","cc","memory"\
    )

/**
 * 处理1个参数
 */
#define API_ENTRY_PARE1(nr,rets,pval1) \
asm volatile(\
         "move a7, %[sysnr]\n\t"\
         "move a0, %[prv1]\n\t"\
         "ecall \n\t"\
		 "move %[retval], a0 \n\t"\
         :[retval] "=r" (rets)\
         :[sysnr] "r" (nr),[prv1]"r" (pval1)\
         :"a7","a0","cc","memory"\
    )

/**
 * 处理2个参数
 */
#define API_ENTRY_PARE2(nr, rets, pval1, pval2) \
asm volatile(\
         "move a7, %[sysnr]\n\t"\
         "move a0, %[prv1]\n\t"\
         "move a1, %[prv2]\n\t"\
         "ecall \n\t"\
		 "move %[retval], a0 \n\t"\
         :[retval] "=r" (rets)\
         :[sysnr] "r" (nr),[prv1]"r" (pval1),\
		 [prv2]"r" (pval2)\
         :"a7","a0","a1","cc","memory"\
    )

/**
 * 处理3个参数
 */
#define API_ENTRY_PARE3(nr, rets, pval1, pval2, pval3) \
asm volatile(\
         "move a7, %[sysnr]\n\t"\
         "move a0, %[prv1]\n\t"\
         "move a1, %[prv2]\n\t"\
         "move a2, %[prv3]\n\t"\
         "ecall \n\t"\
		 "move %[retval], a0 \n\t"\
         :[retval] "=r" (rets)\
         :[sysnr] "r" (nr), \
         [prv1]"r" (pval1),\
		 [prv2]"r" (pval2),\
		 [prv3]"r" (pval3)\
         :"a7","a0","a1","a2","cc","memory"\
    )

/**
 * 处理4个参数
 */
#define API_ENTRY_PARE4(nr, rets, pval1, pval2, pval3, pval4) \
asm volatile(\
         "move a7, %[sysnr]\n\t"\
         "move a0, %[prv1]\n\t"\
         "move a1, %[prv2]\n\t"\
         "move a2, %[prv3]\n\t"\
         "move a3, %[prv4]\n\t"\
         "ecall \n\t"\
		 "move %[retval], a0 \n\t"\
         :[retval] "=r" (rets)\
         :[sysnr] "r" (nr),[prv1]"r" (pval1),\
		 [prv2]"r" (pval2),\
		 [prv3]"r" (pval3),\
		 [prv4]"r" (pval4)\
         :"a7","a0","a1","a2","a3","cc","memory"\
    )

/**
 * 处理5个参数
 */
#define API_ENTRY_PARE5(nr, rets, pval1, pval2, pval3, pval4, pval5) \
asm volatile(\
         "move a7, %[sysnr]\n\t"\
         "move a0, %[prv1]\n\t"\
         "move a1, %[prv2]\n\t"\
         "move a2, %[prv3]\n\t"\
         "move a3, %[prv4]\n\t"\
         "move a4, %[prv5]\n\t"\
         "ecall \n\t"\
		 "move %[retval], a0 \n\t"\
         :[retval] "=r" (rets)\
         :[sysnr] "r" (nr),[prv1]"r" (pval1),\
		 [prv2]"r" (pval2),\
		 [prv3]"r" (pval3),\
		 [prv4]"r" (pval4),\
		 [prv5]"r" (pval5)\
         :"a7","a0","a1","a2","a3","a4","cc","memory"\
    )

/**
 * 处理6个参数
 */
#define API_ENTRY_PARE6(nr, rets, pval1, pval2, pval3, pval4, pval5, pval6) \
asm volatile(\
         "move a7, %[sysnr]\n\t"\
         "move a0, %[prv1]\n\t"\
         "move a1, %[prv2]\n\t"\
         "move a2, %[prv3]\n\t"\
         "move a3, %[prv4]\n\t"\
         "move a4, %[prv5]\n\t"\
         "move a5, %[prv6]\n\t"\
         "ecall \n\t"\
		 "move %[retval], a0 \n\t"\
         :[retval] "=r" (rets)\
         :[sysnr] "r" (nr),[prv1]"r" (pval1),\
		 [prv2]"r" (pval2),\
		 [prv3]"r" (pval3),\
		 [prv4]"r" (pval4),\
		 [prv5]"r" (pval5),\
		 [prv6]"r" (pval6)\
         :"a7","a0","a1","a2","a3","a4","a5","cc","memory"\
    )

#endif
